//
//  ProgressHUD.m
//  SVProgressHUD
//
//  Created by edz on 2019/8/14.
//  Copyright © 2019年 edz. All rights reserved.
//

#import "ProgressHUD.h"
#import <MBProgressHUD/MBProgressHUD.h>

@implementation ProgressHUD

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
MBProgressHUD *hud = nil;
+ (void)showText:(NSString *)text icon:(UIImage *)icon mode:(MBProgressHUDMode)mode onView:(UIView *)view duration:(CGFloat)duration
{
    if (view == nil) {
        view = [UIApplication sharedApplication].delegate.window;
    }
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.detailsLabel.text = text;
    if (mode != MBProgressHUDModeText) {
        hud.mode = mode;
    } else {
        if (icon == nil) {
            hud.mode = MBProgressHUDModeText;
        } else {
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:icon];
        }
    }
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.removeFromSuperViewOnHide = YES;
    if (duration != 10.0) {
        [hud hideAnimated:YES afterDelay:duration];
    }
    hud.margin = 10;
    [self setupHUDAppearance:hud];
}

+ (void)setupHUDAppearance:(MBProgressHUD *)hud
{
    hud.detailsLabel.font = [UIFont systemFontOfSize:15];
    //        hud.detailsLabel.textColor = [UIColor whiteColor];
    //    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    //    hud.bezelView.backgroundColor = [UIColor brownColor];
}
+ (void)dismiss{
    hud.hidden = YES;
}
@end
